package main

import (
	"fmt"
	"io/ioutil"
	"ks3Demo/aes"
	"os"
	"time"
)

//export Encrypter
func Encrypter(keyPath string, srcPath string, isDeleteSrc bool) string {

	startT := time.Now()
	keyFile, _ := os.Open(keyPath)
	keyStr, keyErr := ioutil.ReadAll(keyFile)
	var outPath = ""
	if keyErr == nil {
		aes.InitializeBlock(keyStr)
		outPath, error := aes.Encrypter(srcPath, isDeleteSrc)
		if error != nil {
			fmt.Println(error)
		}
		return outPath
	}
	tc := time.Since(startT) //计算耗时
	fmt.Printf("time cost = %v\n", tc)
	return outPath
}

//export Decrypter
func Decrypter(keyPath string, srcPath string, isDeleteSrc bool) (outPath string) {
	startT := time.Now()
	keyFile, _ := os.Open(keyPath)
	keyStr, keyErr := ioutil.ReadAll(keyFile)
	if keyErr == nil {
		aes.InitializeBlock(keyStr)
		outPath,_ = aes.Decrypter(srcPath, isDeleteSrc)
		return  outPath
	}else {
		return "";
	}
	tc := time.Since(startT) //计算耗时
	fmt.Printf("time cost = %v\n", tc)
	return ""
}

func main() {

	//enFlag := Encrypter("/Users/cqc/Desktop/qunarsec.qunarsec","/Users/cqc/data/临时文件/upload/a.txt",false)
	//fmt.Printf("", enFlag)
	outPath := Decrypter("/Users/cqc/Desktop/qunarsec.qunarsec", "/private/var/folders/s0/bllrt37j7hn6lv01krwmpz380000gn/T/aessdk_889899435", false)
	fmt.Printf("", outPath)
}
